package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.CartService;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Address;
import com.itheima.reggie.domain.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CartController {

    @Autowired
    private CartService cartService;
    //保存菜品到购物车后
    @PostMapping("/cart/add")
    public ResultInfo save(@RequestBody Cart cart){
        Cart cartFromDB= cartService.save(cart);
        return ResultInfo.success(cartFromDB);
    }


    //查询
    @GetMapping("/cart/list")
    public ResultInfo find(){
       List<Cart> list=cartService.find();
       return ResultInfo.success(list);
    }


    //删除
    @DeleteMapping("/cart/clean")
    public ResultInfo deleted(){
        cartService.deleted();
        return ResultInfo.success(null);
    }


    //购物车减数量
    @PostMapping("/cart/sub")
    public ResultInfo put(@RequestBody Cart cart){
       Cart cart1= cartService.put(cart);
       return ResultInfo.success(cart1);
    }


}
